package com.ja.openchat.ui.me;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import com.ja.openchat.BR;
import com.ja.openchat.R;
import com.ja.openchat.databinding.FragmentWithdrawalBinding;
import com.ja.openchat.viewmodels.WithdrawalViewModel;
import com.ja.openchat.views.DigitTextWatcher;

import me.goldze.mvvmhabit.base.BaseFragment;

//提现界面
public class WithdrawalFragment extends BaseFragment<FragmentWithdrawalBinding, WithdrawalViewModel> {

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_withdrawal;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initView() {
        super.initView();
        new DigitTextWatcher(binding.etMoney) {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                super.onTextChanged(s, start, before, count);
                viewModel.money.set(s.toString());
                viewModel.enable.set(!TextUtils.isEmpty(s));
            }
        };
        binding.tvSubmit.setOnClickListener(v -> {
            float value = 0.00f;
            try {
                value = !TextUtils.isEmpty(viewModel.money.get()) ? Float.parseFloat(viewModel.money.get()) : 0.00f;
            } catch (Exception e) {
                e.printStackTrace();
            }
            viewModel.withdraw(value, getActivity());
        });
    }
}